package com.ruoyi.pingjiao.utils;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.pingjiao.mapper.CourseAssessNameMapper;
import com.ruoyi.pingjiao.service.CourseAssessNameService;
import com.ruoyi.pingjiao.service.impl.CourseAssessNameServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
@Component
public class MathData {

    @Autowired
    private  CourseAssessNameService service;
    private static CourseAssessNameService courseAssessNameService;
//    @Resource
//    public void setService(CourseAssessNameService courseAssessNameService){
//        MathData.courseAssessNameService=courseAssessNameService;
//    }
     @PostConstruct
     public void init(){
         courseAssessNameService=service;
     }
    //完成率
    public static Double finishData(List<Integer>list,Integer integer,Integer courseId){
        double percent = 0.00;
//        switch (integer){
//            case 1:
                //查询目标下的考核评价比例
                //percent.get(0)*list(0)

//        CourseAssessNameService courseAssessNameService=new CourseAssessNameServiceImpl();
               List<Integer>percentList=courseAssessNameService.selectPercentByCourseAssessId(integer,courseId);
               System.out.println(percentList);
               double sum=0;
//               int percents=0;
        if(percentList.size()!=0){
               for(int i=0;i<list.size();i++){

//                       sum=sum+(list.get(i)*percentList.get(i));
//                       percents=percents+percentList.get(i);
                   double percentList_double = percentList.get(i) / 100.0;
                   sum = sum + (list.get(i) * percentList_double);

               }
//               percent=sum/percents;
            percent = sum / percentList.get(percentList.size()-1);
        }
//              double a=list.get(0)*0.07+list.get(1)*0.11+list.get(2)*0.13;
//                percent=a/31;
//              break;
//            case 2:
//              double b=list.get(0)*0.15+list.get(1)*0.10;
//                percent=b/25;
//                break;
//            case 3:
//              double c=list.get(0)*0.07+list.get(1)*0.05;
//                percent=c/12;
//              break;
//            case 4:
//              double d=list.get(0)*0.12+list.get(1)*0.08+list.get(2)*0.12;
//              percent=d/32;
//              break;
//        }
     return percent;
    }
    //平均数
    public static Double average(List<Double>integers){
        double num=0;
        for(int i=0;i<integers.size();i++){
            num+=integers.get(i);
        }
        return num/integers.size();
    }
    //中间值
    public static Double middle(List<Double>integers){
        double middle=0;
        Double[]array=new Double[integers.size()];
        for(int i=0;i<integers.size();i++){
            array[i]=integers.get(i);
        }
//        Integer[] objects = (Integer[]) integers.toArray();
        for(int i=1;i<array.length;i++){
            for (int j=0;j<i;j++){
                if(array[j]>array[i]){
                    double a=array[j];
                    array[j]=array[i];
                    array[i]=a;
                }
            }
        }
        if(array.length%2==0){
            int i=array.length/2;
            double num=array[i-1]+array[i];
            middle=num/2;
        }else{
            int i= (array.length-1)/2;
            middle=array[i];
        }
        return middle;
    }
    //标准偏差
    public static Double piancha(List<Double>integers){
        Double average = average(integers);
        double value=0.0;
        for(int i=0;i<integers.size();i++){
            value+=Math.pow(integers.get(i)-average,2);
        }
        return Math.sqrt(value/integers.size());
    }
    //最大值
    public static Double max(List<Double>integers){
        double max=integers.get(0);
        for (Double integer:integers
             ) {
            if(max<integer){
                max=integer;
            }
        }
        return max;
    }
    //最小值
    public static Double min(List<Double>integers){
        double min=integers.get(0);
        for (Double integer:integers
        ) {
            if(min>integer){
                min=integer;
            }
        }
        return min;
    }
}
